<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:hh="http://www.w3.org/1999/xhtml"
      xmlns:jsp="http://java.sun.com/JSP/Page">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>动力金融网-CFCA认证的互联网金融公司</title>
<script type="text/javascript" th:src="@{/js/jquery-1.7.2.min.js}"></script>
<script type="text/javascript" th:src="@{/js/trafficStatistics.js}"></script>
<link rel="stylesheet" type="text/css" th:href="@{/css/style.css}" />
<link rel="stylesheet" type="text/css" th:href="@{/css/share.css}" />
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" />

</head>

<body>
<div id="header">
<!--<jsp:include page="commons/header.jsp"/>-->
    <div th:include="commons/header :: html"></div>
</div>

<!--散标投资 begin-->
<div id="sbtz" class="invest-details">

<!--页中begin-->
<div class="mainBox pro-details-body">
  <div class="homeWap clearfix" id="huacengPar">
    <div class="pro-details-left">

      <!-- 产品详情start -->
      <div class="pro-info-details">
        <div class="pro-name">
          <h2><span th:text="|${loanInfoByTypeId.productName}(${loanInfoByTypeId.productNo}期)|">季度宝 (20170726期)</span></h2>
        </div>
        <div class="pro-info">
          <ul class="clearfix">
            <li class="info-1">
              <p>历史年化利率</p>
              <h3 th:text="|${loanInfoByTypeId.rate}%|">4.9%</h3>
              <div class="info-bt">
              <span>本产品采用普通利率</span>
              </div>
            </li>
            <li class="info-2">
              <p>募集金额(元)</p>
              <h3 th:text="${loanInfoByTypeId.productMoney}">500000.0</h3>
              <div class="info-bt">
              	<span th:text="|募集中,剩余募集金额${loanInfoByTypeId.leftProductMoney}元|">
              		<!-- 只有状态为0时为募集，其它都为已满标 -->
              		募集中,剩余募集金额 500000.0元
              		<!-- 已满标 -->
              	</span>
              </div>
            </li>
            <li class="info-3">
              <p>投资周期</p>
              <!-- 只有新手宝产品周期为天 -->
              <h3 th:text="${loanInfoByTypeId.productType==0?loanInfoByTypeId.cycle+'天':loanInfoByTypeId.cycle+'个月'}">6个月</h3>
              <div class="info-bt"><span></span></div>
            </li>
          </ul>
        </div>
        <dl class="pro-syfs">
          <dt><span>收益获取方式</span></dt>
          <dd><span>收益返还：</span>到期还本付息</dd>
        </dl>
      </div>
      <!-- 产品详情end -->
      
      <!-- 投资记录start -->
      <div class="pro-details-cnt">
        <ul class="tabNav clearfix">
          <li><a id="one3" href="javascript:void(0);" class="s">投资记录</a></li>
        </ul>

        <div class="invest-record" id="con_one_3" style="display:block">
        <div class="vertical-side">投资列表</div>
		<dl class="record-list">
		<dt>
			<span class="record-num">序号</span><span class="invest-user">投资人</span><span class="invest-money">投资金额(元)</span><span class="invest-time">投资时间</span>
		</dt>
          <div th:if="${#lists.isEmpty(incomeRecordList)}">
            <!-- 如果投资记录为空，显示以下文字 -->
            <dd style="text-align:center;">该产品暂时还没有人投资，赶快去投资吧~</dd>
          </div>
          <span th:if="${!#lists.isEmpty(incomeRecordList)}"><!--有值则遍历-->
            <span th:each="bidInfo,bidInfoStat:${incomeRecordList}">
              <dd>
                <span class="record-num" th:text="${bidInfoStat.count}">1</span>
                <span class="invest-user" th:text="|${#strings.substring(bidInfo.user.phone,0,3)}****${#strings.substring(bidInfo.user.phone,8,11)}|">137******89</span>
                <span class="invest-money" th:text="${bidInfo.bidMoney}">1000.0</span>
                <span class="invest-time" th:text="${#dates.format(bidInfo.bidTime,'yyyy-MM-dd hh:mm:ss')}">2017-09-12 13:34:22</span>
              </dd>
            </span>
          </span>
		</dl>
		</div>
      </div>
      <!-- 投资记录end -->
    </div>
    
    <!--页面右侧begin-->
    <div class="pro-details-right">
      <div class="right-calculator" id="huaceng">
        <div class="calculator-cnt">
          <h2>立即投资</h2>
          <dl class="profits-mode">
            <dt>收益获取方式</dt>
            <dd class="clearfix"><span id="fanhuan"><em>到期还本付息</em></span></dd>
          </dl>
          <dl class="usable">
            <dt>我的账户可用</dt>
            <dd>资金(元)：
            <span th:if="${session.user}">
              <!-- 判断用户是否登录：已登录，显示可用余额 -->
             <span style="font-size:18px;color:#ff6161;vertical-align:bottom;" th:text="|${session.user.financeAccount.availableMoney}元|">1,000,12 元</span>
            </span>

            <span th:unless="${session.user}">
              <!-- 判断用户是否登录：未登录，显示登录连接 -->
              <span style="font-size:18px;color:#ff6161;vertical-align:bottom;"><a th:href="@{/loan/page/login}">请登录</a></span>
            </span>
	           		<!--<span style="font-size:18px;color:#ff6161;vertical-align:bottom;">1,000,12 元</span>-->
	        </dd>
          </dl>
          <div class="expect-box">
            <div class="expect-money">预计本息收入(元)：<span id="shouyi" class="money"></span><span class="prompt" style="display:block;">请在下方输入投资金额</span></div>
            <input type="text" id="bidMoney" name="bidMoney" onblur="checkMoney();" placeholder="请输入投资金额，应为100元的整倍数" maxlength="9"/>
            <div class="max-invest-money"></div>
          </div>
          <div class="invest-btn">
          	<a id="investNow" href="javascript:void(0)" class="btn-1" onclick="invest();">立即投资</a>
          </div>
          <input type="hidden" id="loanId" name="loanId" value="${loanInfo.id}"/>
        </div>
      </div>
    </div>
    <!--页面右侧end-->
  </div>
</div>

<!--页中end-->

</div>
<!--散标投资 end-->

<!--遮罩层-->
<div class="dialog-overlay" id="dialog-overlay1" style="display:none;"></div>

<!--投资成功浮层start-->
<div class="layer-body failureSuccess failurePayment" id="failurePayment" style="display:none;width:500px;height:100px;top:75%;">
  <a class="layer-close" href="javascript:closeit();"></a>
  <div style="background:#f2f2f2; line-height:105px;text-align:center;"><font style="font-size:25px;">投资成功</font></div>
</div>
<!--投资成功浮层end-->

<!--页脚start-->
<!--<jsp:include page="commons/footer.jsp"/>-->
<div th:include="commons/footer :: html"></div>
<!--页脚end-->

<script type="text/javascript" th:inline="javascript">
function closeit() {
	$("#failurePayment").hide();
	$("#dialog-overlay1").hide();
	window.location.href="${pageContext.request.contextPath}/loan/myCenter";
}
function checkMoney() {
  //获取需要查看利息的产品类型：
  var ptype = [[${loanInfoByTypeId.productType}]];
  //产品的利息
  var rate = [[${loanInfoByTypeId.rate}]];
  //产品的周期
  var cycle = [[${loanInfoByTypeId.cycle}]];
  //获取输入框的值
  var bidMoney = $.trim($("#bidMoney").val());
  //剩余可投资金额
  var leftMoney = [[${loanInfoByTypeId.leftProductMoney}]];

  if(bidMoney % 100 !=0){//输入的值必须是100的整数倍
    $(".max-invest-money").html("必须是100的整倍数！");
    return ;
  }
  if(bidMoney <= 0){
    $(".max-invest-money").html("必须是正整数！");
    return;
  }
  if(bidMoney>=leftMoney){
    alert("超过产品可投资金额，请调整！");
    return
  }
  //计算收益
  var income = null;
  if(ptype ==0){//新手宝：新手宝的周期是 天
    income = bidMoney * (rate/365/100) * cycle
  }else{
    income = bidMoney * (rate/365/100) * cycle * 30
  }
  income = Math.round(income*Math.pow(10,2))/Math.pow(10,2);
  $(".max-invest-money").html(income);
}

//投资验证
function invest() {

  var user = [[${session.user}]];
  //获取文本框输入的金额
  var money = $.trim($("#bidMoney").val());
  //获取该产品的最低投资金额：
  var minMoney = [[${loanInfoByTypeId.bidMinLimit}]];
  //获取该产品的最高投资金额
  var maxMoney = [[${loanInfoByTypeId.bidMaxLimit}]];
  //获取该产品id
  var loanId = [[${loanInfoByTypeId.id}]];

  if(user ==null){
    alert("您尚未登录，请登录！");
    return;
  }else {//如果session中有user
    //判断用户是否实名认证
    var name = user.name;
    if(!name){//说明没有值，则表明没有实名认证
      alert("您尚未实名认证，请认证");
      window.location.href="/dev/realName";
      return;
    }
    //投资 金额 不得高于 可用 余额
    //获取可投资金额
    var availableMoney = user.financeAccount.availableMoney;
    if(money>availableMoney){
      alert("您的余额不足，请充值！");
      return;
    }
    //验证  ： money 大于minMoney; 小于 maxMoney
    if(money < minMoney){
      $(".max-invest-money").html("投资金额小于最低限投金额！");
      return;
    }
    if(money > maxMoney){
      $(".max-invest-money").html("投资金额大于最高限投金额！");
      return;
    }
    //如果可头金额为0，禁止投资，投资金额小于等于产品地剩余可投资金额


    //验证成功后，进行投资
    //进行投资 ：要进行变更的表：
    //投标信息产品表：剩余可投资金额，
    // 用户收益记录表
    //用户财务资金表
    $.ajax({
      url:"/dev/invest",
      data:{
        "money":money,//投资金额
        "loanId":loanId //投资的该产品的id
      },
      success:function (data) {
        //跳转到个人中心
        if(data.code ==1){
         window.location.href ="/dev/index";
        }else{
          alert(data.message)
        }
      },
      error:function () {
        $(".max-invest-money").html("系统繁忙，请重试！");
      }
    })
  }
}
</script>
</body>
</html>